package com.example.framework2002a.view.view;

import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import com.example.framework2002a.R;
import com.example.framework2002a.bean.MyTabBean;
import com.example.framework2002a.databinding.ActivityMain2Binding;
import com.example.framework2002a.view.fragment.HeadlinesFragment;
import com.example.framework2002a.view.fragment.HomeFragment;
import com.example.framework2002a.view.fragment.MeFragment;
import com.example.framework2002a.view.fragment.VideoFragment;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity {

    private ActivityMain2Binding binding;
    private ArrayList<CustomTabEntity> entities = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        //----沉溺式布局
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE
                        |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
            //透明导航栏
            //getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        }else {

        }

        binding = DataBindingUtil.setContentView(this,R.layout.activity_main2);

        entities.add(new MyTabBean("首页",0,0));
        entities.add(new MyTabBean("视频",0,0));
        entities.add(new MyTabBean("微头条",0,0));
        entities.add(new MyTabBean("我的",0,0));
        binding.main2Comm.setTabData(entities);
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.main2_fl,new HomeFragment())
                .commit();
        binding.main2Comm.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                switch (position){
                    case 0:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.main2_fl,new HomeFragment())
                                .commit();
                        break;
                    case 1:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.main2_fl,new VideoFragment())
                                .commit();
                        break;
                    case 2:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.main2_fl,new HeadlinesFragment())
                                .commit();
                        break;
                    case 3:
                        getSupportFragmentManager()
                                .beginTransaction()
                                .replace(R.id.main2_fl,new MeFragment())
                                .commit();
                        break;
                }

            }

            @Override
            public void onTabReselect(int position) {

            }
        });
    }
}